package com.king.hive.etl.mapper;

import com.king.hive.etl.util.ETLUtil;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class EtlMapper extends Mapper<LongWritable, Text, Text, NullWritable> {
    private Text k = new Text();

    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        //获取一行
        String line = value.toString();
        //清洗
        String resultData = ETLUtil.etlData(line);

        if (resultData != null) {
            //写出
            k.set(resultData);
            context.write(k, NullWritable.get());
        }
    }
}
